package tr.gov.tubitak.bilgem.esya.certviewer.viwerasn;

import sun.security.x509.Extension;
import tr.gov.tubitak.bilgem.esya.certviewer.Bundle;
import tr.gov.tubitak.bilgem.esya.certviewer.EByteTools;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: ramazan.girgin
 * Date: 08.12.2011
 * Time: 13:41
 * To change this template use File | Settings | File Templates.
 */
public class EQCStatementExtension implements ECertExtension {
    Extension extension;
    boolean isParsed=false;
    String strValue;
    //QCStatementExtension qcStatementExtension;
    @Override
    public String getName() {
        return Bundle.getString("EQCStatementExtension.Name");
    }

    @Override
    public String getShortTitle() {
        if(extension != null)
        {
            if(!isParsed){
                parseExtension();
            }
        }
        return strValue;
    }

    private void parseExtension() {
        byte[] extensionValue = extension.getExtensionValue();
        strValue= EByteTools.toHexString(extensionValue," ");
        try {
            QCStatementExtension qcStatementExtension = new QCStatementExtension(isCritical(),extensionValue);
            strValue = qcStatementExtension.toString();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        catch (Exception e)
        {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    @Override
    public String getLongTitle() {
        return getShortTitle();
    }

    @Override
    public boolean isCritical() {
        if(extension == null){
            return false;
        }
        return extension.isCritical();
    }

    @Override
    public void encode(byte[] data) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setAsnObject(Object asnObject) {
        if(asnObject instanceof Extension){
            extension = (Extension) asnObject;
        }
    }
}
